var FooVision = {

    username: '',

    withFriends: false,

    checkerUrl: '',
    
    interval: 0,

    numImages: 0,
    
    lastUpdate: 0,

    cur: '',

    setUsername: function(u) {
        this.username = u;
    },

    setWithFriends: function(wf) {
        this.withFriends = wf;
    },

    setChecker: function(url) {
        this.checkerUrl = url;
    },

    setInterval: function(i) {
        this.interval = i;
    },
    
    setNumImages: function(n) {
        this.numImages = n;
    },
    
    start: function() {
        this.lastUpdate = 0;
        this.cur = 'img1';
        setTimeout('FooVision.check()', this.interval * 1000);
    },


    check: function() {
        // Call to checker
        new Ajax.Request(this.checkerUrl, 
                            { method: 'get',
                              
                              parameters: {
                                username: this.username, 
                                last_update: this.lastUpdate,
                                with_friends: this.withFriends
                              },
                              
                              onSuccess: function(transport, data){
                                  data.each(
                                            function(item) {
                                                $('imagename').innerHTML = item.name;
                                                $('sender').innerHTML = item.sender;
                                                $('node').innerHTML = item.node;
                                                $('createtime').innerHTML = item.createtime;
                                                var past = FooVision.cur;
                                                if (FooVision.cur == 'img1') {
                                                    $('img1aux').setAttribute('src', item.urlSq); 
                                                    new Effect.Puff($('img1'));
                                                    new Effect.Appear($('img1aux'));
                                                    FooVision.cur = 'img1aux';
                                                } else {
                                                    $('img1').setAttribute('src', item.urlSq); 
                                                    new Effect.Puff($('img1aux'));
                                                    new Effect.Appear($('img1'));
                                                    FooVision.cur = 'img1';
                                                }
                                                // Move prev images
                                                for (var i = FooVision.numImages; i > 2; i--) {
                                                    $('img' + i).setAttribute('src', $('img' + (i-1)).src);
                                                }
                                                $('img2').setAttribute('src', $(past).src);
                                                
                                                FooVision.lastUpdate = item.createtime;
                                            });
                              }
                            });
        setTimeout('FooVision.check()', this.interval * 1000);
    }
    
}

